<%@page language="java" pageEncoding="utf-8" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="m" uri="/cutm_tags"%>
<head>
<title>Sql查询数据库</title>
<script type="text/javascript">
$(document).ready(function(){
	$('#paymentBtn').click(function() {
		//$.confirm('确定下载查询结果文件吗？', function(){
			$('#downloadForm').submit();
		//});
	});
	$('td').each(function(){
		var str=$.trim($(this).text());
		var length=str.length;
		if(length>3&&str.substring(length-3,length)=='.00'){;
			$(this).text(str.substring(0,length-3));
		}
	});
});
</script>
</head>
<body>
<a href="<s:url action="log/ViewLog"/>">下载日志文件</a>
<s:form action="sql/SqlQuery" id="query">
	<h3>请输入Sql查询语句</h3>
	<table class="form">
		<tr>
			<td><s:textarea id="sql" cssClass="required" name="sql" /></td>
		</tr>
	</table>
	<div class="buttonGroup"><input type="submit" value="查询" /></div>
</s:form>
<s:if test="results.columnNames.length>0">
	<h3>查询结果</h3>
</s:if>
<table class="list">
	<thead>
		<tr>
			<s:iterator value="results.columnNames" status="status">
				<th><s:property value="results.columnNames[#status.index-1]" /></th>
			</s:iterator>
		</tr>
	</thead>
	<tbody>
		<s:iterator value="results.items" id="type" status="status">
			<s:set name="resultSet" value="#type" />
			<tr>
				<s:if test="#resultSet.length>1">
					<s:set name="length" value="#resultSet.length" />
					<s:iterator value="#resultSet" status="status">
						<s:if test="results.current!=0">
							<s:if test="#status.index<#length">
								<td><s:property value="#resultSet[#status.index-1]" /></td>
							</s:if>
						</s:if>
						<s:else>
							<td><s:property value="#resultSet[#status.index-1]" /></td>
						</s:else>
					</s:iterator>
				</s:if>
				<s:else>
					<td><s:property value="#resultSet" /></td>
				</s:else>
			</tr>
		</s:iterator>
	</tbody>
</table>
<!--   <div class="buttonGroup"><m:page value="${results}" showSeaBar="true" /></div>-->
<s:if test="results!=null">
	<div class="buttonGroup"><input id="paymentBtn" type="button" value="下载查询结果文件" /></div>
	<div style="display: none"><s:form id="downloadForm" cssClass="readOnly" action="sql/SqlDownload!toExport">
		<s:textarea name="sql" />
	</s:form></div>
</s:if>
</body>
